/*  BEGIN_FILE_HDR
******************************************Copyright(C)*****************************************
*
*                                       YKXH  Technology
*
***********************************File Info***************************************************
*   File Name       @: CanTp.h
************************************************************************************************
*   Project/Product @: CANTP
*   Title           @: CanTp module Header File
*   Author          @: zhongliang.Yang 
************************************************************************************************
*   Description     @: 
*                   
************************************************************************************************
*   Limitations     @: None
*
************************************************************************************************
*
************************************************************************************************
*   Revision History:
* 
*   Version     Date          Initials           CR#         Descriptions
*   --------    -----------   ----------------   --------    -----------------------
*   1.0         2018/05/29    zhongliang.yang    N/A         Original 
*   1.1         xxxx/xx/xx    xxxxx              N/A         xxxxxxxx 
*     
************************************************************************************************
* END_FILE_HDR*/

#ifndef _CANTP_H_
#define _CANTP_H_

/**************************************************************************************************
* Include files
**************************************************************************************************/

#include "CanTp_Cfg.h"
#include "CanTp_Cbk.h"


#define CANTP_VENDOR_ID             (uint16)(0xFFFFu)  /*Supplier ID */
#define CANTP_MODULE_ID             (uint16)(0x0023u)  /*CanTp Moudle ID */

/* CanTp Component release Version  */
#define CANTP_SW_MAJOR_VERSION      (uint8)(0x01u)
#define CANTP_SW_MINOR_VERSION      (uint8)(0x00u)
#define CANTP_SW_PATCH_VERSION      (uint8)(0x00u)
/* Autosar release version */
#define CANTP_AR_MAJOR_VERSION      (uint8)(0x04u)
#define CANTP_AR_MINOR_VERSION      (uint8)(0x00u)
#define CANTP_AR_PATCH_VERSION      (uint8)(0x00u)

/**************************************************************************************************
* Global data types and structures
**************************************************************************************************/
/* AUTOSAR compliant */

typedef enum /* CanTpInternalState */
{
  CANTP_OFF = 0,
  CANTP_ON
} CanTpInternalState;

typedef enum
{
  CANTP_RX_CHANNEL = 0,
  CANTP_TX_CHANNEL
} CanTpChannelType;


typedef enum
{
  CANTP_STANDARD = 0,
  CANTP_EXTENDED,
  CANTP_MIXED
} CanTpAddressingFormat;

typedef enum
{
  CANTP_PHYSICAL = 0,
  CANTP_FUNCTIONAL
} CanTpTaType;

typedef enum
{
  CANTP_BS_PARAMETER = 0,
  CANTP_STMIN_PARAMETER
} CanTpParameterType;


/************************************************
* Types for static-configuration (ROM/Flash) 
************************************************/
/*************
* CanTp (ROM) 
*************/
typedef struct /*RxNsdu (ROM)*/ 
{ 
    PduIdType      CanTpChannelId;
    PduIdType      CanTpRxNPduId;    /* from CanIf */
    PduIdType      CanTpTxFcNPduId;  /* to   CanIf */
    uint16         CanTpRxDl;
    uint16         CanTpNar;
    uint16         CanTpNbr;
    uint16         CanTpNcr;  
    uint8          CanTpRxPaddingActive;
    uint8          CanTpRxTaType;
    uint8          CanTpRxAddrFormat;
    uint8          CanTpBs;
    uint8          CanTpSTmin;
    uint8          CanTpRxWftMax;
    uint8          CanTpRxNAe;
    uint8          CanTpRxNSa;
    uint8          CanTpRxNTa;
} CanTp_RxNsduCfgType;

typedef struct /*TxNsdu (ROM)*/
{ 
    PduIdType      CanTpChannelId;
    PduIdType      CanTpTxNPduId;    /* to   CanIf */
    PduIdType      CanTpRxFcNPduId;  /* from CanIf */
    uint16         CanTpTxDl;
    uint16         CanTpNas;
    uint16         CanTpNbs;
    uint16         CanTpNcs;
    uint8          CanTpTxPaddingActive;
    uint8          CanTpTxTaType;
    uint8          CanTpTxAddrFormat;
    uint8          CanTpTxNAe;
    uint8          CanTpTxNSa;
    uint8          CanTpTxNTa;
} CanTp_TxNsduCfgType;

typedef struct /*RxPdu mapping table */
{
    PduIdType RxSduIdx;
    PduIdType TxSduIdx;
} CanTp_RxPduMapType;

typedef struct
{
   boolean  CanTpChannelMode;
}CanTpChannelModeType;

/* *********************************************** */
/* CanTp Overall (ROM)                             */
/* *********************************************** */
typedef struct /* Struct to hold the complete CanTp-configuration */
{ 
    CONSTP2CONST(CanTp_RxNsduCfgType,TYPEDEF,TYPEDEF) CanTp_RxNsduCfg;
    CONSTP2CONST(CanTp_TxNsduCfgType,TYPEDEF,TYPEDEF) CanTp_TxNsduCfg;
    CONSTP2CONST(CanTpChannelModeType,TYPEDEF,TYPEDEF) CanTpChannelMode;
} CanTp_CfgType;
/* *********************************************** */
/* External administration data (RAM)              */
/* *********************************************** */
typedef struct 
{
    P2CONST(CanTp_CfgType,TYPEDEF,TYPEDEF) CfgPtr;
    CanTpInternalState InternalState; /* keep track of the initialization status */
} CanTp_AdminDataType;

/**************************************************************************************************
* Global defines
**************************************************************************************************/

#define CANTP_MODE_HALF_DUPLEX      0x00
#define CANTP_MODE_FULL_DUPLEX      0x01
#define CANTP_MAX_FRAME_LENGTH      0x08u    /* CAN frame max length*/
#define CANTP_UNUSED                         0xFFu


/**************************************************************************************************
* Gloable Data definitions
**************************************************************************************************/
#define CANTP_START_SEC_CONFIG_DATA_UNSPECIFIED
#include "../src/BSW/CommS/NM/YKBase/MemMap.h"

extern CONST(CanTp_CfgType,CANTP_CONFIG_CONST) CanTp_Cfg;

#define CANTP_STOP_SEC_CONFIG_DATA_UNSPECIFIED
#include "../src/BSW/CommS/NM/YKBase/MemMap.h"
/**************************************************************************************************
* Prototypes of export functions
**************************************************************************************************/
#define CANTP_START_SEC_PUBLIC_CODE
#include "../src/BSW/CommS/NM/YKBase/MemMap.h"

extern FUNC(void,CANTP_PUBLIC_CODE) CanTp_Init
(
    CONSTP2CONST(void, AUTOMATIC, CANTP_CONFIG_CONST) pCfgPtr
);

extern FUNC(void,CANTP_PUBLIC_CODE) CanTp_Shutdown(void);
extern FUNC(void,CANTP_PUBLIC_CODE) CanTp_MainFunction(void);
extern FUNC(Std_ReturnType,CANTP_PUBLIC_CODE) CanTp_Transmit
(
    PduIdType CanTpTxSduId,
    P2CONST(PduInfoType,AUTOMATIC,CANTP_CONST) CanTpTxInfoPtr
);
#if (CANTP_TC == STD_ON)
extern FUNC(Std_ReturnType,CANTP_PUBLIC_CODE) CanTp_CancelTransmitRequest
(
    PduIdType CanTpTxSduId
);
#endif
extern FUNC(Std_ReturnType,CANTP_PUBLIC_CODE) CanTp_CancelReceiveRequest
(
    PduIdType CanTpRxSduId
);
extern FUNC(Std_ReturnType,CANTP_PUBLIC_CODE) CanTp_ChangeParameterRequest
(
    PduIdType CanTpSduId,
    CanTpParameterType parameter,
    uint16 value
);

#if (CANTP_VERSION_INFO_API == STD_ON)
extern FUNC(void,CANTP_PUBLIC_CODE) CanTp_GetVersionInfo
(
    P2VAR(Std_VersionInfoType,AUTOMATIC,CANTP_NOINIT_DATA) pVersionInfo
);
#endif                                                     
#define CANTP_STOP_SEC_PUBLIC_CODE
#include "../src/BSW/CommS/NM/YKBase/MemMap.h"

#endif/* ifndef CANTP_H */

/*******************************************************************************
 *  END OF FILE: CanTp.h
 ******************************************************************************/ 

